﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.API;
namespace JumbotCms.WebFile.Admin.Cut2Thumb
{
    public partial class _index : AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ChannelId = Str2Str(q("ccid"));
            Admin_Load("", "html", true);
            string FrameName = q("fname");
            string TempPhoto = q("tphoto");
            string ToWidth = q("tow");
            string ToHeight = q("toh");
            string CutType = q("type");
            if (CutType == "1")//手工裁剪
            {
                string printhtml = "";
                printhtml += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\r\n";
                printhtml += "<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n";
                printhtml += "<head>\r\n";
                printhtml += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n";
                printhtml += "<title>图片裁剪</title>\r\n";
                printhtml += "</head>\r\n";
                printhtml += "<frameset rows=\"30,*\" cols=\"*\" framespacing=\"0\" frameborder=\"no\" border=\"0\">\r\n";
                printhtml += "<frame src=\"process.aspx?ccid=" + ChannelId + "&tphoto=" + TempPhoto + "&tow=" + ToWidth + "&toh=" + ToHeight + "\" name=\"topFrame\" id=\"topFrame\" />\r\n";
                printhtml += "<frame src=\"preview.aspx?ccid=" + ChannelId + "&tphoto=" + TempPhoto + "&tow=" + ToWidth + "&toh=" + ToHeight + "\" name=\"mainFrame\" scrolling=\"auto\" noresize=\"noresize\" id=\"mainFrame\" />\r\n";
                printhtml += "</frameset>\r\n";
                printhtml += "<noframes><body>\r\n";
                printhtml += "</body>\r\n";
                printhtml += "</noframes></html>\r\n";
                Response.Write(printhtml);
            }
            else//自动缩放
            {
                string fileExtension = ".jpg"; //缩略图后缀名
                string strXmlFile = HttpContext.Current.Server.MapPath("~/_data/config/upload_admin.config");
                Jumbot.DataOper.XmlControl XmlTool = new Jumbot.DataOper.XmlControl(strXmlFile);
                string sUserUploadPath = XmlTool.GetText("Module/" + ChannelType + "/path");
                XmlTool.Dispose();
                string DirectoryPath;

                DirectoryPath = site.Dir + ChannelDir + sUserUploadPath + "/" + DateTime.Now.ToString("yyyy-MM");
                Jumbot.Common.DirFile.CreateDir(site.Dir + ChannelDir + sUserUploadPath + "/" + DateTime.Now.ToString("yyyy-MM"));

                string sFileName = "thumb_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + fileExtension;  // 文件名称
                string thumbnailPath = Server.MapPath(DirectoryPath + "/" + sFileName);        // 服务器端文件路径

                //以jpg格式保存缩略图
                Jumbot.Common.ImageHelp.MakeThumbPhoto(Server.MapPath(TempPhoto), thumbnailPath, Convert.ToInt32(ToWidth), Convert.ToInt32(ToHeight), "Cut");
                Response.Write("<script>window.opener.document.getElementById('txtImg').value='" + DirectoryPath + "/" + sFileName + "';window.close();</script>");
            }
        }
    }
}
